var twoSumTarget = function (nums, target) {
  // nums 数组必须有序
  nums.sort((a, b) => a - b);
  let lo = 0, hi = nums.length - 1;
  const res = [];
  while (lo < hi) {
    let sum = nums[lo] + nums[hi];
    let left = nums[lo], right = nums[hi];
    if (sum < target) {
      // 跳过重复的元素
      while (lo < hi && nums[lo] == left) lo++;
    } else if (sum > target) {
      // 跳过重复的元素
      while (lo < hi && nums[hi] == right) hi--;
      // 缩小窗口
    } else {
      res.push([left, right]);
      // 跳过重复的元素 
      while (lo < hi && nums[lo] == left) lo++;
      while (lo < hi && nums[hi] == right) hi--;
    }
  }
  return res;
};